home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
FANGS__
/
OFFSETNU.C
< prev
next >
Wrap
Text File
|
1990-05-26
|
4KB
|
163 lines
/* ⌐ 1990 Patrick Doane. */
#include <OffsetNum.h>
#include <Utilities.h>
extern GrafPtr scratchPort;
void OffsetNum::IOffsetNum(WindowPtr theWindow,Rect *theBounds,
short theCurrentValue,short theMinValue,short theMaxValue,
short theStepValue,VoidFunc theChangeProc,long theDelay)
{
Graphic::IGraphic(theWindow,theBounds);
clickOK = true;
arrowHandle = (SICNHand)GetResource('SICN',128);
SetRect(&arrowBounds,bounds.left+18,bounds.top,bounds.left+34,
bounds.top+16);
currentValue = theCurrentValue;
offset = 0;
minValue = theMinValue;
maxValue = theMaxValue;
stepValue = theStepValue;
if (theChangeProc != 0L)
changeProc = theChangeProc;
else
changeProc = DefaultProc;
timeDelay = theDelay;
}
void OffsetNum::SetBounds(Rect *theBounds)
{
bounds = *theBounds;
SetRect(&arrowBounds,bounds.left+18,bounds.top,bounds.left+34,
bounds.top+16);
}
void OffsetNum::SetValue(short theValue,Boolean addOffset,Boolean redraw)
{
if (addOffset)
currentValue = theValue + offset;
else
currentValue = theValue;
if (currentValue < minValue)
currentValue = minValue;
if (currentValue > maxValue)
currentValue = maxValue;
if (redraw)
UpdateText();
}
void OffsetNum::Update(void)
{
Rect theBounds;
UpdateText();
theBounds = arrowBounds;
PlotSICN(&theBounds,arrowHandle,0);
}
void OffsetNum::UpdateText(void)
{
Rect theBounds;
Str255 theString;
GrafPtr savePort;
if (currentValue == 0x8000)
return;
GetPort(&savePort);
SetPort(scratchPort);
theBounds = bounds;
theBounds.right -= 16;
EraseRect(&theBounds);
MoveTo(theBounds.left,theBounds.top+12);
NumToString((long)currentValue,theString);
TextFont(savePort->txFont);
DrawString(theString);
SetPort(savePort);
CopyBits(&scratchPort->portBits,&thePort->portBits,&theBounds,
&theBounds,srcCopy,0L);
}
void OffsetNum::DoClick(EventRecord *theEvent)
{
Rect theRect;
Str255 theString;
Boolean oldState = true,newState;
Point mouseLoc;
if (!active)
return;
theRect = arrowBounds;
theRect.bottom -= 8;
theRect.right -= 7;
if (PtInRect(theEvent->where,&theRect))
{ InvertRect(&theRect);
Increase();
while (TrackMouse(&mouseLoc,&theRect,&newState,timeDelay))
{ if (newState != oldState)
{ InvertRect(&theRect);
oldState = newState;
}
if (oldState)
Increase();
}
if (oldState)
InvertRect(&theRect);
}
theRect = arrowBounds;
theRect.top += 8;
theRect.right -= 7;
if (PtInRect(theEvent->where,&theRect))
{ InvertRect(&theRect);
Decrease();
while (TrackMouse(&mouseLoc,&theRect,&newState,timeDelay))
{ if (newState != oldState)
{ InvertRect(&theRect);
oldState = newState;
}
if (oldState)
Decrease();
}
if (oldState)
InvertRect(&theRect);
}
}
void OffsetNum::Increase(void)
{
(*changeProc)(this,DoIncrease);
}
void OffsetNum::Decrease(void)
{
(*changeProc)(this,DoDecrease);
}
void DefaultProc(register OffsetNum *theOffsetNum,short theParam)
{
switch (theParam)
{ case DoIncrease:
if (theOffsetNum->currentValue + theOffsetNum->stepValue >
theOffsetNum->maxValue)
return;
theOffsetNum->currentValue += theOffsetNum->stepValue;
theOffsetNum->offset += theOffsetNum->stepValue;
theOffsetNum->UpdateText();
break;
case DoDecrease:
if (theOffsetNum->currentValue - theOffsetNum->stepValue <
theOffsetNum->minValue)
return;
theOffsetNum->currentValue += theOffsetNum->stepValue;
theOffsetNum->offset += theOffsetNum->stepValue;
theOffsetNum->UpdateText();
break;
}
}